<template>
  <div>
    <div>{{tx}}
      <select v-model="tx">
        <option :value=-0.3>学习缓慢</option>
        <option :value=0>无特性</option>
        <option :value=0.3>学习神速</option>
      </select>
    </div>
    <div>
      初始烹饪等级<select v-model="lv_p">
        <option v-for="v in [0,1,2,3,4]" :key="v" :value="v">{{v}}</option>
      </select>获得经验加成{{ (base1st(lv_p) * 100) | tofixed(0) }}%
    </div>
    <div>
      初始木工等级<select v-model="lv_m">
        <option v-for="v in [0,1,2,3,4]" :key="v" :value="v">{{v}}</option>
      </select>获得经验加成{{ (base1st(lv_m) * 100) | tofixed(0) }}%
    </div>
    <div>
      初始钓鱼等级<select v-model="lv_y">
        <option v-for="v in [0,1,2,3,4]" :key="v" :value="v">{{v}}</option>
      </select>获得经验加成{{ (base1st(lv_y) * 100) | tofixed(0) }}%
    </div>
    <div>
      初始耕作等级<select v-model="lv_g">
        <option v-for="v in [0,1,2,3,4]" :key="v" :value="v">{{v}}</option>
      </select>获得经验加成{{ (base1st(lv_g) * 100) | tofixed(0) }}%
    </div>
    <div>
      初始搜寻等级<select v-model="lv_s">
        <option v-for="v in [0,1,2,3,4]" :key="v" :value="v">{{v}}</option>
      </select>获得经验加成{{ (base1st(lv_s) * 100) | tofixed(0) }}%
    </div>
    <div>
      初始诱捕等级<select v-model="lv_l">
        <option v-for="v in [0,1,2,3,4]" :key="v" :value="v">{{v}}</option>
      </select>获得经验加成{{ (base1st(lv_l) * 100) | tofixed(0) }}%
    </div>

    <table border>
      <tr>
        <td>现有等级</td>
        <td v-for="v in 10" :key="v">{{ v-1 }}</td>
      </tr>
      <tr>
        <td>固有经验</td>
        <td v-for="v in 10" :key="v">{{inherExp( v-1 , 0 ) }}</td>
      </tr>
      <tr>
        <td>升级所需经验</td>
        <td v-for="v in 10" :key="v">{{needExp( v - 1 ) }}</td>
      </tr>

    </table>

    <table border>
      <tr>
        <td></td>
        <td v-for="v in 9" :key="v">
          {{ v }}
        </td>
      </tr>
      <tr>
        <td>每日节目经验（烹饪）</td>
        <td v-for="v in 9" :key="v">{{ dayExp(v,'厨') }}</td>
      </tr>
      <tr>
        <td>当日节目后实际获取经验</td>
        <td v-for="(v,k) in 厨艺经验" :key="k">
          <div>{{v.exp | tofixed(0) }}</div>
        </td>
      </tr>
      <tr>
        <td>当日可能（或不可能）升级后的等级</td>
        <td v-for="(v,k) in 厨艺经验" :key="k">
          <!-- <pre>{{v}}</pre> -->
          <div :class="{
            'red':(v.lv % 2)==0,
            'bold':(v.lv % 2)==0,
          }">{{ v.lv }}</div>
        </td>
      </tr>
      <tr>
        <td>当日可能（或不可能）升级后的剩余经验</td>
        <td v-for="(v,k) in 厨艺经验" :key="k">
          <div>{{v.yu | tofixed(0) }}</div>
        </td>
      </tr>

      <tr>
        <td>每日节目经验（木工）</td>
        <td v-for="v in 9" :key="v">{{ dayExp(v,'木') }}</td>
      </tr>
      <tr>
        <td>当日节目后实际获取经验</td>
        <td v-for="(v,k) in 木工经验" :key="k">
          <div>{{v.exp | tofixed(0) }}</div>
        </td>
      </tr>
      <tr>
        <td>当日可能（或不可能）升级后的等级</td>
        <td v-for="(v,k) in 木工经验" :key="k">
          <!-- <pre>{{v}}</pre> -->
          <div :class="{
            'red':(v.lv % 2)==0,
            'bold':(v.lv % 2)==0,
          }">{{ v.lv }}</div>
        </td>
      </tr>
      <tr>
        <td>当日可能（或不可能）升级后的剩余经验</td>
        <td v-for="(v,k) in 木工经验" :key="k">
          <div>{{v.yu | tofixed(0) }}</div>
        </td>
      </tr>
      <tr>
        <td>钓鱼</td>
        <td v-for="(v,k) in 钓鱼经验" :key="k">
          <!-- <pre>{{v}}</pre> -->
          <div :class="{
            'red':(v.lv % 2)==0,
            'bold':(v.lv % 2)==0,
          }">{{ v.lv }}</div>
        </td>
      </tr>
      <tr>
        <td>耕作</td>
        <td v-for="(v,k) in 耕作经验" :key="k">
          <!-- <pre>{{v}}</pre> -->
          <div :class="{
            'red':(v.lv % 2)==0,
            'bold':(v.lv % 2)==0,
          }">{{ v.lv }}</div>
        </td>
      </tr>
      <tr>
        <td>搜索</td>
        <td v-for="(v,k) in 搜索经验" :key="k">
          <!-- <pre>{{v}}</pre> -->
          <div :class="{
            'red':(v.lv % 2)==0,
            'bold':(v.lv % 2)==0,
          }">{{ v.lv }}</div>
        </td>
      </tr>
      <tr>
        <td>诱捕</td>
        <td v-for="(v,k) in 诱捕经验" :key="k">
          <!-- <pre>{{v}}</pre> -->
          <div :class="{
            'red':(v.lv % 2)==0,
            'bold':(v.lv % 2)==0,
          }">{{ v.lv }}</div>
        </td>
      </tr>

      <!--
      <tr>
        <td>每日节目经验（木工）</td>
        <td v-for="v in 9" :key="v">{{ dayExp(v,'木') }}</td>
      </tr> -->

    </table>
    {{days}}<br>

  </div>
</template>

<script>
export default {
  name: 'HelloWorld',

  data () {
    return {
      days: (() => {
        return new Array(9).fill(null)
      })(),
      tx: 0.3,
      lv_p: 2,
      lv_m: 3,
      lv_y: 1,
      lv_g: 1,
      lv_s: 2,
      lv_l: 2,
      yhdzz = {
    10: {
      name: '鸢一折纸',
      空间震规模: 'AA', 灵装: 'AA', 天使: 'AAA', 综合危险度: 'AAA',
      力量: 158, 耐力: 152, 灵力: 219, 敏捷: 136, 智力: 243,
    },
    20: {
      name: '本条二亚',
      空间震规模: 'C', 灵装: 'C', 天使: 'S', 综合危险度: 'A',
      力量: 60, 耐力: 59, 灵力: 142, 敏捷: 64, 智力: 245,
    },
    30: {
      name: '时崎狂三',
      空间震规模: 'C', 灵装: 'C', 天使: 'S', 综合危险度: 'S',
      力量: 109, 耐力: 80, 灵力: 220, 敏捷: 103, 智力: 201,
    },
    40: {
      name: '冰芽川四糸乃',
      空间震规模: 'C', 灵装: 'B', 天使: 'AA', 综合危险度: 'B',
      力量: 95, 耐力: 82, 灵力: 199, 敏捷: 212, 智力: 152,
    },
    50: {
      name: '五河琴里',
      空间震规模: 'B', 灵装: 'A', 天使: 'AA', 综合危险度: 'AA',
      力量: 160, 耐力: 100, 灵力: 215, 敏捷: 130, 智力: 178,
    },
    60: {
      name: '星宫六喰',
      空间震规模: 'AAA', 灵装: 'A', 天使: 'S', 综合危险度: 'AAA',
      力量: 142, 耐力: 121, 灵力: 205, 敏捷: 138, 智力: 67,
    },
    70: {
      name: '镜野七罪',
      空间震规模: 'B', 灵装: 'C', 天使: 'AA', 综合危险度: 'B',
      力量: 79, 耐力: 65, 灵力: 180, 敏捷: 82, 智力: 174,
    },
    81: {
      name: '八舞夕弦',
      空间震规模: 'AA', 灵装: 'B', 天使: 'AA', 综合危险度: 'AAA',
      力量: 170, 耐力: 129, 灵力: 185, 敏捷: 240, 智力: 84,
    },
    82: {
      name: '八舞耶俱矢',
      空间震规模: 'AA', 灵装: 'B', 天使: 'AA', 综合危险度: 'AAA',
      力量: 180, 耐力: 140, 灵力: 179, 敏捷: 240, 智力: 69,
    },
    90: {
      name: '诱宵美九',
      空间震规模: 'B', 灵装: 'C', 天使: 'AA', 综合危险度: 'A',
      力量: 85, 耐力: 72, 灵力: 159, 敏捷: 67, 智力: 70,
    },
    100: {
      name: '夜刀神十香',
      空间震规模: 'B', 灵装: 'AAA', 天使: 'AAA', 综合危险度: 'AAA',
      力量: 230, 耐力: 202, 灵力: 125, 敏捷: 142, 智力: 32,
    },
  }
    }
  },
  computed: {
    厨艺经验: function () {
      return this.everyDay('厨')
    },
    木工经验: function () {
      return this.everyDay('木')
    },
    钓鱼经验: function () {
      return this.everyDay('渔')
    },
    耕作经验: function () {
      return this.everyDay('耕')
    },
    搜索经验: function () {
      return this.everyDay('搜')
    },
    诱捕经验: function () {
      return this.everyDay('猎')
    }
  },
  filters: {
    tofixed (n, m) {
      return Number(n.toFixed(m))
    },
    nlv (arg) {
      // let lv = arg[0]
      let yu = arg[1]
      let need = arg[2]
      return `${yu}/${need}`
    }
  },
  methods: {
    base1st (lv) {
      let r = 1 + [0, 0.75, 1.00, 1.25, 1.25][lv] + this.tx
      return r
    }, // 初始职业可以获得的加成
    inherExp (lv, prev) {
      if (lv === 0) {
        return prev
      } else {
        prev += this.needExp(lv - 1)
        return this.inherExp(lv - 1, prev)
      }
    },
    book (lv) { return [3, 3, 5, 5, 8, 8, 12, 12, 16, 16][lv] },
    needExp (lv) {
      return [
        75, 150, 300, 750,
        1.5 * Math.pow(10, 3), // 4
        3.0 * Math.pow(10, 3), // 5
        4.5 * Math.pow(10, 3), // 6
        6.0 * Math.pow(10, 3), // 7
        7.5 * Math.pow(10, 3), // 8
        9.0 * Math.pow(10, 3) // 9
      ][lv]
    },
    dayExp (day, type) {
      return {
        1: { '厨': 112.5, '木': 75, '渔': 62.5 },
        2: { '厨': 75, '木': 75, '耕': 62.5 },
        3: { '厨': 62.5, '木': 100, '渔': 52.5 },
        4: { '厨': 87.5, '木': 75 },
        5: { '厨': 75, '木': 112.5, '搜': 50 },
        6: { '厨': 62.5, '木': 100, '猎': 112.5 },
        7: { '厨': 87.5, '木': 112.5, '搜': 100 },
        8: { '厨': 125, '木': 37.5 },
        9: { '厨': 75 }
      }[day][type] || 0
    },
    dayGetExp ({day, type, lvBase, lvNow}) {
      let baseExp = this.dayExp(day, type)
      let a = this.book(lvNow) || 1
      let b = this.base1st(lvBase) || 1
      return baseExp * a * b
    },
    up ({lv, exp}) {
      if (lv >= 10) { return null }
      let need = this.needExp(lv)

      if (exp < need) {
        return [lv, exp, need]
      } else {
        let nLv = lv + 1
        let nExp = exp - need
        return this.up({lv: nLv, exp: nExp})
      }
    },
    everyDay: function (type) {
      // return this.days.reduce((t, v, i, a) => {
      //   let n = 0
      //   if (i === 0) { n = 1 }
      //   if (i === 1) { n = 1 }
      //   if (i > 1) { n = t[i - 2] + t[i - 1] }
      //   t.push(n)
      //   console.log('%c [ t ]-257', 'font-size:13px; background:pink; color:#bf2c9f;', t)
      //   return t
      // }, [])

      return this.days.reduce((t, v, i, a) => {
        let lvBase = ((type) => {
          if (type === '厨') { return this.lv_p }
          if (type === '木') { return this.lv_m }
          if (type === '渔') { return this.lv_y }
          if (type === '耕') { return this.lv_g }
          if (type === '搜') { return this.lv_s }
          if (type === '猎') { return this.lv_l }
        })(type)
        let exp = this.dayGetExp({
          day: i + 1,
          type: type,
          lvBase: lvBase,
          lvNow: (i === 0) ? lvBase : t[i - 1].lv
        })
        let now = this.up({
          lv: ((i === 0) ? lvBase : t[i - 1].lv),
          exp: (exp + ((i === 0) ? 0 : t[i - 1].yu))
        })
        t.splice(i, 1, {exp: exp, lv: now[0], yu: now[1]})
        return t
      }, [])
    }

  }
}
</script>

<style scoped>
.bold{font-weight: bold;}
.red{color:red};
.bg-red{ background:red}
</style>
